using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.ServiceCore.Services.IService;

namespace ZR.Admin.WebApi.Controllers.System
{
    /// <summary>
    /// 测试表2管理
    /// </summary>
    [Verify]
    [Route("system/sheetTest2")]
    [ApiExplorerSettings(GroupName = "sys")]
    public class SheetTest2Controller : BaseController
    {
        private readonly ISheetTest2Service SheetTest2Service;

        public SheetTest2Controller(ISheetTest2Service sheetTest2Service)
        {
            SheetTest2Service = sheetTest2Service;
        }

        /// <summary>
        /// 测试表2管理 -> 获取测试表2列表
        /// /system/sheetTest2/list
        /// </summary>
        /// <param name="pager">分页参数</param>
        /// <returns></returns>
        [HttpPost("list")]
        public IActionResult List([FromQuery] PagerInfo pager)
        {
            var queryDto = new SheetTest2QueryDto(); // 创建空的查询条件
            var list = SheetTest2Service.SelectSheetTest2List(queryDto, pager);
            return SUCCESS(list);
        }

        /// <summary>
        /// 测试表2管理 -> 根据ID获取测试表2信息
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        [HttpGet("{id:int}")]
        [ActionPermissionFilter(Permission = "system:sheetTest2:query")]
        public IActionResult GetInfo(int id)
        {
            var info = SheetTest2Service.SelectSheetTest2ById(id);
            return SUCCESS(info);
        }

        /// <summary>
        /// 测试表2管理 -> 添加测试表2
        /// </summary>
        /// <param name="addDto">添加对象</param>
        /// <returns></returns>
        [HttpPost("add")]
        [Log(Title = "测试表2管理", BusinessType = BusinessType.INSERT)]
        [ActionPermissionFilter(Permission = "system:sheetTest2:add")]
        public IActionResult Add([FromBody] SheetTest2AddDto addDto)
        {
            if (addDto == null)
            {
                return ToResponse(ApiResult.Error(101, "请求参数错误"));
            }

            var result = SheetTest2Service.AddSheetTest2(addDto);
            return SUCCESS(result);
        }

        /// <summary>
        /// 测试表2管理 -> 修改测试表2
        /// </summary>
        /// <param name="updateDto">修改对象</param>
        /// <returns></returns>
        [HttpPut("edit")]
        [Log(Title = "测试表2管理", BusinessType = BusinessType.UPDATE)]
        [ActionPermissionFilter(Permission = "system:sheetTest2:edit")]
        public IActionResult Edit([FromBody] SheetTest2UpdateDto updateDto)
        {
            if (updateDto == null || updateDto.Id <= 0)
            {
                return ToResponse(ApiResult.Error(101, "请求参数错误"));
            }

            var result = SheetTest2Service.UpdateSheetTest2(updateDto);
            return SUCCESS(result);
        }

        /// <summary>
        /// 测试表2管理 -> 删除测试表2
        /// </summary>
        /// <param name="ids">主键ID数组</param>
        /// <returns></returns>
        [HttpDelete("remove/{ids}")]
        [Log(Title = "测试表2管理", BusinessType = BusinessType.DELETE)]
        [ActionPermissionFilter(Permission = "system:sheetTest2:remove")]
        public IActionResult Remove(string ids)
        {
            if (string.IsNullOrEmpty(ids))
            {
                return ToResponse(ApiResult.Error(101, "请求参数错误"));
            }

            var idArray = ids.Split(',').Select(int.Parse).ToArray();
            var result = SheetTest2Service.DeleteSheetTest2(idArray);
            return SUCCESS(result);
        }

        /// <summary>
        /// 测试表2管理 -> 导出测试表2数据
        /// </summary>
        /// <param name="queryDto">查询条件</param>
        /// <returns></returns>
        [HttpGet("export")]
        [Log(Title = "测试表2管理", BusinessType = BusinessType.EXPORT)]
        [ActionPermissionFilter(Permission = "system:sheetTest2:export")]
        public IActionResult Export([FromQuery] SheetTest2QueryDto queryDto)
        {
            var pager = new PagerInfo { PageNum = 1, PageSize = 10000 }; // 导出时获取所有数据
            var list = SheetTest2Service.SelectSheetTest2List(queryDto, pager);
            
            // 这里可以添加导出逻辑，比如导出为Excel
            // 暂时返回数据列表
            return SUCCESS(list.Result);
        }
    }
}
